<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="js/base.js"></script>
	</head>
	<body>
		<img id="icon"/>
		<input id="iconFile" type="file"/>
		
		<img id="showImage"/>
		<button onclick="onShowImageClick();">显示图片</button>
		
		<img src="http://localhost:8080/wuye/XiaoQuController/showImage?fileName=C03CF038EC8E4B588C057CB3EE0CFC69.jpg"/>
		
		<script>
			function onShowImageClick(){
				
				let url="http://localhost:8080/wuye/UserController/showImg?fileName=";
				url=url+"5D331812749147728696C5E09F1D5040.jpg";
				
				rest(url,"get",null,function(r){
					document.getElementById("showImage").src="data:image/png;base64,"+r.data;
				});
				
			}
			
			
			
			
			
			let iconFile=document.getElementById("iconFile");
			iconFile.onchange=function(){
				handleFile(iconFile.files);
			};
			function handleFile(files){
				if(files.length>1){
					return;
				}
				if(files[0]){
					//把选择的文件直接展示在前端
					let srcValue=window.URL.createObjectURL(files[0]);
					document.getElementById("icon").src=srcValue;
					//要把选择的文件转成base64，传给后端
					let reader=new FileReader();
					reader.onload=function(){
						let base64=this.result;
						//上传服务器，或者打印看看
						console.info(base64);
						//rest();
					};
					reader.readAsDataURL(files[0]);
				}
			}
		</script>
	</body>
</html>